package cn.zhouyafeng.itchat4j.game;


import cn.zhouyafeng.itchat4j.api.MessageTools;
import cn.zhouyafeng.itchat4j.core.GlobalConfig;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * 猜数字
 */
public class GuessNumberGame {

    /**
     * 存储答案 <群ID，答案>
     */
    private static Map<String,Integer> result = new HashMap<>();

    public static void start(String key){
        Integer num = new Random().nextInt(100);
        result.put(key,num);
        System.out.println(GameEnum.GUESS_NUMBER.getDesc() +" :" + key +" " + num);
        GlobalConfig.currGameMap.put(key,GameEnum.GUESS_NUMBER.getCode());
        MessageTools.sendMsgById("猜数字游戏已启动，请说出你的答案范围：1～100", key);
    }
    public static void end(String key){
        result.remove(key);
        GlobalConfig.currGameMap.remove(key);
        MessageTools.sendMsgById("本轮猜数字游戏已结束", key);
    }

    /**
     * 对比答案
     * @param key
     * @param n
     * @return
     */
    public static int compare(String key,Integer n){
        Integer num = result.get(key);
        result.put(key,num);
        return n.compareTo(num);
    }





    public static void main(String[] args) {
//        for (int i=0;i<20;i++){
//            System.out.println(new Random().nextInt(100));
//        }


    }


}
